package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AddNursingProjectDto;
import com.zzyl.dto.NursingProjectQueryDto;
import com.zzyl.dto.UpdateNursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="护理项目")
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;


    @ApiOperation("护理项目分页查询")
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> page(NursingProjectQueryDto dto){
        PageResponse<NursingProjectVo> page = nursingProjectService.pageQuery(dto);
        return ResponseResult.success(page);
    }

    @ApiOperation("新增护理项目")
    @PostMapping
    public ResponseResult add(@RequestBody AddNursingProjectDto dto){
        nursingProjectService.add(dto);
        return ResponseResult.success();
    }

    @ApiOperation("根据id查询项目详情")
    @GetMapping("{id}")
    public ResponseResult<NursingProject> getById(@PathVariable("id")Long id){
        NursingProject nursingProject = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProject);
    }

    @ApiOperation("根据id修改项目详情")
    @PutMapping
    public ResponseResult update(@RequestBody UpdateNursingProjectDto dto){
        nursingProjectService.update(dto);
        return ResponseResult.success();
    }

    @ApiOperation("根据id删除项目")
    @DeleteMapping("{id}")
    public ResponseResult delete(@PathVariable("id")Long id){
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult status(@PathVariable("id")Long id, @PathVariable("status")Integer status){
        nursingProjectService.status(id, status);
        return ResponseResult.success();
    }

    @ApiOperation("查询所有的护理项目")
    @GetMapping("/all")
    public ResponseResult<List<NursingProject>> all(){
        List<NursingProject> all = nursingProjectService.all();
        return ResponseResult.success(all);
    }


}

